<template>
	<view>
		<view class="mainpadding2 ffffff">
			<u-tabs :list="tabs" lineColor="#1BA95B" @click="changetab" :activeStyle="{
				    color: '#1BA95B',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'
				}" :inactiveStyle="{
				            color: '#333333',
							fontWeight: '400',
				            transform: 'scale(1)'
				        }" itemStyle="padding-left: 5px; padding-right: 10px; height: 44px;"></u-tabs>
		</view>
		<!-- 内容 -->
		<view class="mainpadding2">
			<view class="flexcenter" v-if="!list.data.length">
				<view class="placeholderimage" style="margin-top: 300rpx;" ></view>
			</view>
			<template v-if="tabsid!=6">
				
				<view class="mainpadding_top ffffff radius"  v-for="item in list.data" :key="item.id" @click="jumpurl('/pages_mypage/changdiddxq?id=',item.id)">
					<view class="flexbetween xiahuaxian">
						<view class="titletext sanshier xiaohei fonweight">{{item.order_no}}</view>
						<!-- 0=全部,1=待付款,2=待核销,3=已完成,4=已取消,5=已退费 -->
						<view class="xiaolv strongtext" v-if="item.status==1">待付款</view>
						<view class="xiaolv strongtext" v-if="item.status==2">待核销</view>
						<view class="xiaohui strongtext" v-if="item.status==3">已完成</view>
						<view class="xiaolv strongtext" v-if="item.status==4">已取消</view>
						<view class="xiaolv strongtext" v-if="item.status==5">已退费</view>
						<view class="xiaohuang strongtext" v-if="item.status==6">取消审核中</view>
					</view>
					<view class="xiahuaxian margin_top">
						<view class="flexbetween">
							<view class="shilitu margin_right2">
								<image :src="item.image_text" mode=""></image>
							</view>
							<view class="flexcolumn" style="width: 69%;align-items: flex-start;height: 160rpx;justify-content: space-between;">
								<view class="titletext xiaohei fonweight yhxk">{{item.name}}</view>
								<view class="flexbetween margin_top2" style="width: 100%;">
									<view class="flexleft" >
										<view class="sanshier xiaohong fonweight">￥{{item.pay_price}}</view>
									</view>
									<!-- <view class="titletext">x19</view> -->
								</view>
							</view>
						</view>
					</view>
					<view class="flexright margin_top">
						<view class="baibtn " v-if="item.status==1" @click.stop="cancelitem(item.id)">取消订单</view>
						<view class="lvbtn margin_left" v-if="item.status==1" @click.stop="payorder(item)">继续付款</view>
						<view class="baibtn" v-if="item.status==4 || item.status==3 || item.status==5 " @click.stop="delitem(item.id)">删除订单</view>
						<view class="lvbtn margin_left" v-if="item.status==2 || item.status==6" >查看详情</view>
					</view>
				</view>
			</template>
			<template v-if="tabsid==6">
				<view class="margin_top xiahuaxian" v-for="item in list.data" :key="item.id">
					<view class="flexbetween ">
						<view class="flexleft">
							<view class="touxiang margin_right2">
								<image :src="item.user.avatar_text" mode=""></image>
							</view>
							<view class="">
								<view class="titletext fonweight xiaohei">{{item.user.nickname}}</view>
								<view class="strongtext nofonweight xiaohui">{{item.createtime_text}}</view>
							</view>
						</view>
						<view class="flexright">
							<u-icon name="star-fill" color="#F8B900" size="22" v-for="ite in item.score"
								:key="ite"></u-icon>
						</view>
						<!-- <u-icon name="star" color="#999999" size="22"></u-icon> -->
					</view>
					<view class="margin_top2 xiaohei ershiba nofonweight">{{item.content}}</view>
					<view class="flexleft flex_wrap">
						<view class="sanshis flexcenter margin_top2" v-for="(ite,inde) in item.images_text" :key="inde">
							<view class="jiaolt">
								<image :src="ite" mode="" @click="lbtpriview(inde,item.images_text)"></image>
							</view>
						</view>
					</view>
					<view class="flexleft margin_top">
						<view class="shilitu2 margin_right2">
							<image :src="item.cgorder.image_text" mode=""></image>
						</view>
						<view class="titletext xiaohei fonweight yhxk">{{item.cgorder.name}}</view>
					</view>
					<view class="flexright margin_top">
						<view class="lvbtn" @click="jumpurl('/pages_mypage/bianjipj?type=3&id=',item.id)">编辑评价</view>
					</view>
				</view>
			</template>
		</view>
		
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				// :0=全部,1=待付款,2=待核销,3=已完成,4=已取消,5=已退费
				tabs: [{
						name: '全部',
						value: 0,
					},
					{
						name: '待付款',
						value: 1
					},
					{
						name: '待核销',
						value: 2
					},
					{
						name: '已完成',
						value: 3
					},
					{
						name: '已取消',
						value: 4
					},
					{
						name: '已退费',
						value: 5
					},
					{
						name: '我的评价',
						value: 6
					}
				],
				tabsid: 0,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			lbtpriview(index, arr) {
				var i = arr; //获取当前页面的轮播图数据
				//uniapp预览轮播图
				uni.previewImage({
					current: index, //预览图片的下标
					urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
				})
			},
			payorder(item) {
				uni.navigateTo({
					url: '/pages_homepage/zhifu?type=4&price=' + item.pay_price + "&id=" +
						item.id
				})
			},
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
					status:this.tabsid
				}
				let url = '/api/user/cgOrderIndex'
				if (this.tabsid == 6) { //我的评价
					url = '/api/cgcl/myCgComment'
					delete data.status
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			delitem(id) {
				httpRequest.modal('提示', '确认删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/user/deleteCgOrder', 'GET', {
							id
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg)
							if (res.code == 1) {
								this.init()
							}
						})
					}
				})
			},
			cancelitem(id) {
				httpRequest.modal('提示', '确认取消当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/user/cancelCgOrder', 'GET', {
							id
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg)
							if (res.code == 1) {
								this.init()
							}
						})
					}
				})
			},
			jumpurl(url,id){
				uni.navigateTo({
					url:url+id
				})
			},
			changetab(e) {
				this.tabsid = e.value
				this.list.data = []
				this.init()
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #F9F9F9;
	}
	.shilitu {
		width: 200rpx;
		height: 160rpx;
	
		image {
			width: 100%;
			height: 100%;
		}
	}
	.shilitu2 {
		width: 150rpx;
		height: 110rpx;
	
		image {
			width: 100%;
			height: 100%;
		}
	}
</style>